const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path')
module.exports = {
  mode: 'development',
  devtool: false,
  entry: './src/index.js',
  cache: {//1.持久化缓存
    type: 'filesystem', // 'money'|'filesystem',缓存type，内存或硬盘，默认内存
    cacheDirectory: path.resolve(__dirname, 'node_modules/.cache/webpack')// 缓存地址
  },
  optimization: {
    //4.chunkids和moduleids
    chunkIds: 'deterministic',
    moduleIds: 'deterministic'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-react']
            }
          }
        ],
        exclude: /node_modules/
      },
      //2.资源模块替代file-loader,url-loader,raw-loader=>asset/resource,asset/inline,asset/source
      //3.uris没什么用
      {
        test: /\.png$/,
        type: 'asset/resource'
      },
      {
        test: /\.ico$/,
        type: 'asset/inline'
      },
      {
        test: /\.txt$/,
        type: 'asset/source'
      },
      {
        test: /\.jpg$/,
        type: 'asset',
        parser: {
          dataUrlCondition: {
            maxSize: 4 * 1024//4kb
          }
        }
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html'
    })
  ]

}